package day08;

public class test1 {
public static void main(String[] args){
    
    int[] arr = new int[]{1, 2, 3, 4, 5};
    double average = getAverage(arr);
    System.out.println("数组的平均值为：" + average);

    int[] arr2 = new int[]{};
    double average2 = getAverage(arr2);
    System.out.println("数组的平均值为：" + average2);

    int[] arr3 = new int[]{2,-3,5,-6,8,-9,-12};
    double max3 = max(arr3);
    System.out.println("数组的最大值为：" + max3);

    int[] arr4 = null;
    double average4 = getAverage(arr4);
    System.out.println("数组的平均值为：" + average4);

    int[] arr5 = new int[]{-2,-3,-5,-6,-8,-9};
    double max5 = max(arr5);
    System.out.println("数组的最大值为：" + max5);

    int[] arr6 = new int[]{1,2,3};
    int[] expandedArr = expandArray(arr6);
    System.out.print("扩展后的数组：");
    for (int num : expandedArr) {
        System.out.print(num + " ");
    }
    System.out.println();

    int[] arr7 = new int[]{};
    int[] expandedArr2 = expandArray(arr7);
    System.out.println("空数组扩展后的长度：" + expandedArr2.length);

    int[] arr8 = null;
    int[] expandedArr3 = expandArray(arr8);
    System.out.println("null数组扩展后：" + expandedArr3);
    
}
public static double getAverage(int[] arr) {
        if (arr == null || arr.length == 0) {
            return 0.0;
        }
        long sum = 0;
        for (int num : arr) {
            sum += num;
        }
        return (double) sum / arr.length;
    }

    public static double max(int[] arr) {
        if (arr == null || arr.length == 0) {
            return 0.0;
        }
        double max = arr[0];
        for (int num : arr) {
            max = Math.max(max, num);
        }
        return max ;
    }

        public static int[] expandArray(int[] arr) {
        if (arr == null) {
            return null;
        }
        int[] newArr = new int[arr.length * 2];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }

}
